package com.jt.sys.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jt.common.vo.CheckBox;
import com.jt.common.vo.JsonResult;
import com.jt.common.vo.PageObject;
import com.jt.sys.entity.SysRole;
import com.jt.sys.service.SysRoleService;

@Controller
@RequestMapping("/role/")
public class SysRoleController {
	@Autowired
	private SysRoleService sysRoleService;
	@ResponseBody
	@RequestMapping("doDeleteObject")
	public JsonResult doDeleteObject(Integer id){
		
		sysRoleService.deleteObject(id);
		
		return new JsonResult("delete ok");
	}
	
	@RequestMapping("doFindPageObjects")
	@ResponseBody
	public JsonResult doFindPageObjects(String name, Integer pageCurrent) {
		PageObject<SysRole> pageObject = sysRoleService.findPageObjects(name, pageCurrent);
		return new JsonResult(pageObject);
	}
	
	
	@RequestMapping("doFindRoles")
	@ResponseBody
	public JsonResult doFindRoles() {
		List<CheckBox> list = sysRoleService.findRoles();
		return new JsonResult(list);
	}

	
	
	
	@RequestMapping("doSaveObject")
	@ResponseBody
	public JsonResult doSaveObject(
	    		SysRole entity,Integer[] menuIds){//Springmvc底层会把传回的字符串转换为Integer[]数组
	    	sysRoleService.saveObject(entity,menuIds);
	return new JsonResult("save ok");    
	}
	
	@RequestMapping("doUpdateObject")
	@ResponseBody
	public JsonResult doUpdateObject(
			SysRole entity,Integer[] menuIds){//Springmvc底层会把传回的字符串转换为Integer[]数组
		sysRoleService.updateObject(entity,menuIds);
		return new JsonResult("update ok");    
	}
	
	
	@RequestMapping("doFindObjectById")
	@ResponseBody
	 public JsonResult doFindObjectById(Integer id){
	    	Map<String,Object> map=
	    	sysRoleService.findObjectById(id);
	    	return new JsonResult(map);
	 }
	
	@RequestMapping("doRoleListUI")//访问该路径的时候执行该方法，该方法返回值指向一个页面sys/role_list
	public String doRolelistUI() {
		return "sys/role_list";
	}
	
	@RequestMapping("doRoleEditUI")
	public String doRoleEditUI(){
		return "sys/role_edit";
	}
	
}
